#include "settingscaledialog.h"
#include "ui_settingscaledialog.h"
#include "abstractplot2d.h"

SettingScaleDialog::SettingScaleDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SettingScaleDialog)
{
    ui->setupUi(this);
    _plotter = 0;
    connect(ui->applyBtn, SIGNAL(clicked()), this, SLOT(applay()));
}

SettingScaleDialog::~SettingScaleDialog()
{
    delete ui;
}

void SettingScaleDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void SettingScaleDialog::applay()
{
    if (_plotter) {
        Scale scale;

        scale.setMin(ui->minXDSpinBox->value());
        scale.setMax(ui->maxXDSpinBox->value());
        scale.setIncrement(ui->xIncrementDSpinBox->value());
        scale.setMinorTicks(ui->xTicksSpinBox->value());

        _plotter->setScaleX(scale);

        scale.setMin(ui->minYDSpinBox->value());
        scale.setMax(ui->maxYDSpinBox->value());
        scale.setIncrement(ui->yIncrementDSpinBox->value());
        scale.setMinorTicks(ui->yTicksSpinBox->value());

        _plotter->setScaleY(scale);

    }
}

void SettingScaleDialog::setPlotter(AbstractPlot2D *plotter)
{
    if (plotter) {
       _plotter = plotter;
       Scale scale = _plotter->scaleX();

       ui->minXDSpinBox->setValue(scale.min());
       ui->maxXDSpinBox->setValue(scale.max());
       ui->xIncrementDSpinBox->setValue(scale.increment());
       ui->xTicksSpinBox->setValue(scale.minorTicks());

       scale = _plotter->scaleY();

       ui->minYDSpinBox->setValue(scale.min());
       ui->maxYDSpinBox->setValue(scale.max());
       ui->yIncrementDSpinBox->setValue(scale.increment());
       ui->yTicksSpinBox->setValue(scale.minorTicks());
    }
}
